home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / Area.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  4KB  |  192 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Area.c,v 41.11 2000/05/09 20:33:10 mlemos Exp $
  3.  *
  4.  * Area.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1994-1995 Jan van den Baard.
  8.  * (C) Copyright 1994-1995 Jaba Development.
  9.  * All Rights Reserved.
  10.  *
  11.  * Description: Very simple test program for the area class.
  12.  *
  13.  * $Log: Area.c,v $
  14.  * Revision 41.11  2000/05/09 20:33:10  mlemos
  15.  * Bumped to revision 41.11
  16.  *
  17.  * Revision 1.2  2000/05/09 19:58:31  mlemos
  18.  * Merged with the branch Manuel_Lemos_fixes.
  19.  *
  20.  * Revision 1.1.2.1  1998/02/28 17:44:49  mlemos
  21.  * Ian sources
  22.  *
  23.  *
  24.  */
  25.  
  26. /* Execute me to compile with DICE v3.0
  27. dcc Area.c -proto -mi -ms -lbgui
  28. quit
  29. */
  30.  
  31. #include "DemoCode.h"
  32. #include <intuition/icclass.h>
  33.  
  34. #define ID_REDRAW_AREA        1    /* When this ID is encountered we (re-)render the area. */
  35. #define ID_QUIT            2
  36.  
  37. /*
  38. **    Simply took from the old BGUIDemo. Renders a simple
  39. **    integer mandel in the area.
  40. **/
  41. ULONG RenderMandel( struct Window *win, struct IBox *ibox, Object *area, Object *wd )
  42. {
  43.     LONG    zr, zi, ar, ai, dr, di, sr, si, st, x, y, i;
  44.     LONG    xsize, ysize, depth;
  45.     ULONG rc;
  46.  
  47.     depth = win->WScreen->BitMap.Depth;
  48.     xsize = ibox->Width;
  49.     ysize = ibox->Height;
  50.  
  51.     sr = 0x400000 / xsize;
  52.     si = 0x300000 / ysize;
  53.     st = 0x140000 * -2;
  54.     zi = 0x180000;
  55.  
  56.     for (y = ysize - 1; y >= 0; y--)
  57.     {
  58.         zi -= si;
  59.         zr = st;
  60.         for (x = 0; x < xsize; x++)
  61.         {
  62.             i = 0;
  63.             ar = zr;
  64.             ai = zi;
  65.             do {
  66.                 dr = ar >> 10;
  67.                 di = ai >> 10;
  68.                 ai = dr * 2 * di + zi;
  69.                 dr *= dr;
  70.                 di *= di;
  71.                 ar = dr - di + zr;
  72.                 i++;
  73.             } while (( i <= 25 ) && (( dr + di ) <= 0x400000));
  74.             SetAPen(win->RPort, i % (1 << depth));
  75.             WritePixel(win->RPort, x + ibox->Left, y + ibox->Top);
  76.             /*
  77.             **    To keep things simple I sortof duplicated
  78.             **    the event handler here. It simply returns
  79.             **    to the main event handler (below) when
  80.             **    necessary.
  81.             **/
  82.             while ((rc = HandleEvent( wd )) != WMHI_NOMORE)
  83.             {
  84.                 if (rc == ID_REDRAW_AREA || rc == ID_QUIT || rc == WMHI_CLOSEWINDOW)
  85.                     return rc;
  86.             }
  87.  
  88.             zr += sr;
  89.         }
  90.     }
  91.     return( 0L );
  92. }
  93.  
  94. /*
  95. **    Here we go...
  96. **/
  97. void StartDemo(void)
  98. {
  99.     struct Window    *w;
  100.     Object        *Win, *Area, *But;
  101.     ULONG         signal, rc;
  102.     struct IBox    *area_box;
  103.     BOOL         running = TRUE;
  104.  
  105.     /*
  106.     **    Make a window.
  107.     **/
  108.     Win = WindowObject,
  109.         WINDOW_Title,                "AreaClass demo.",
  110.         WINDOW_AutoAspect,        TRUE,
  111.         WINDOW_SmartRefresh,        TRUE,
  112.         WINDOW_AutoKeyLabel,        TRUE,
  113.         WINDOW_MasterGroup,
  114.             VGroupObject, HOffset(4), VOffset(4), Spacing(4),
  115.                 GROUP_BackFill,         SHINE_RASTER,
  116.                 StartMember,
  117.                     /*
  118.                     **    Create AreaClass object.
  119.                     **
  120.                     **    Note the usage of the ICA_TARGET attribute. This is
  121.                     **    required otherwise the object will never notify you
  122.                     **    of size changes!!
  123.                     **/
  124.                     Area = AreaObject,
  125.                         FRM_Type,            FRTYPE_BUTTON,
  126.                         FRM_EdgesOnly,        TRUE,
  127.                        AREA_MinWidth,        40,
  128.                         AREA_MinHeight,    10,
  129.                         GA_ID,                ID_REDRAW_AREA,
  130.                         ICA_TARGET,            ICTARGET_IDCMP,
  131.                     EndObject,
  132.                 EndMember,
  133.                 StartMember,
  134.                     But = FuzzButton("_Quit", ID_QUIT), FixMinHeight,
  135.                 EndMember,
  136.             EndObject,
  137.         EndObject;
  138.  
  139.     /*
  140.     **    OK?
  141.     **/
  142.     if (Win)
  143.     {
  144.         /*
  145.         **    Open the window.
  146.         **/
  147.         if (w = WindowOpen(Win))
  148.         {
  149.             /*
  150.             **    Get window signal.
  151.             **/
  152.             GetAttr(WINDOW_SigMask, Win, &signal);
  153.             /*
  154.             **    Poll messages...
  155.             **/
  156.             do
  157.             {
  158.                 Wait(signal);
  159.                 while ((rc = HandleEvent(Win)) != WMHI_NOMORE)
  160.                 {
  161.  
  162.                     handleMsg:
  163.                     switch ( rc )
  164.                     {
  165.                     case ID_REDRAW_AREA:
  166.                         /*
  167.                         **    Were signalled to redraw the
  168.                         **    area. Obtain the area bounds.
  169.                         **/
  170.                         GetAttr(AREA_AreaBox, Area, (ULONG *)&area_box);
  171.                         /*
  172.                         **    Render inside the area.
  173.                         **    When this routine returns we
  174.                         **    evaluate the return code.
  175.                         **/
  176.                         if (rc = RenderMandel(w, area_box, Area, Win))
  177.                             goto handleMsg;
  178.  
  179.                         break;
  180.  
  181.                     case    WMHI_CLOSEWINDOW:
  182.                     case    ID_QUIT:
  183.                         running = FALSE;
  184.                         break;
  185.                     }
  186.                 }
  187.             } while (running);
  188.         }
  189.         DisposeObject(Win);
  190.     }
  191. }
  192.